<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>apache 不记录指定文件类型日志 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>apache 不记录指定文件类型日志</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Apache/">Apache</a> <a class="article__tag-link" href="/tags/LAMP/">LAMP</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果一个站点访问量特别大，那么访问日志就会很多。但有一些访问日志其实可以忽略掉的，比如网站的一些图片，还有 js，css 等静态对象。而这些文件的访问往往是巨量的，而且即使记录这些日志也没有什么用，如何忽略掉这些访问日志呢？</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;相关配置为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">[root@lamp ~]<span class="comment"># vim /usr/local/apache2/conf/extra/httpd-vhosts.conf</span></div><div class="line"></div><div class="line"></div><div class="line"> SetEnvIf Request_URI \.jpg$ image-request</div><div class="line"> SetEnvIf Request_URI \.JPG$ image-request</div><div class="line"> SetEnvIf Request_URI \.png$ image-request</div><div class="line"> SetEnvIf Request_URI \.js$ image-request</div><div class="line"> SetEnvIf Request_URI \.bmp$ image-request</div><div class="line"> SetEnvIf Request_URI \.css$ image-request</div><div class="line"> SetEnvIf Request_URI \.mid$ image-request</div><div class="line"> SetEnvIf Request_URI \.swf$ image-request</div><div class="line"> SetEnvIf Request_URI \.mmf$ image-request</div><div class="line"> SetEnvIf Request_URI \.wma$ image-request</div><div class="line"> SetEnvIf Request_URI \.midi$ image-request</div><div class="line"> ErrorLog <span class="string">"|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-error_%Y%m%d_log 86400"</span></div><div class="line"> CustomLog <span class="string">"|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400"</span> combined env=!image-request</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：在原来日志配置的基础上，增加了一些 image-request 的定义，比如把 gif 、jpg、bpm、swf、js、css 等结尾的全标记为 image-request 。谈后在配置日志的时候加一个标记 env=!image-request ，这里有个叹号，表示取反，这样就可以把这些忽略了。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Apache/36. apache 不记录指定文件类型日志/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
